Skip to content

feat(cli): os migrate audit-side-copies runs the at-rest side-copy rewrite on the live audit tables and the archive - #33607

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/area-A2-33155
Nov 15, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/area-A2-33155

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread

Fixes #33155

Clause-②: yes (widening)
Metadata-protocol: none

Maintainer quick read

  • What changed: a new operator command, os migrate audit-side-copies, runs plugin-audit's at-rest side-copy rewrite (an approval request's payload_json removed from old audit and activity copies) on the live tables and on the archive. The rewrite's amendments now record that command as their name.
  • Why: feat(approvals,mcp): an approver's agent lists the approvals waiting on them over MCP #33117 shipped the two rewrite functions with no way for an operator to run them, and its round-3 review left the name open until a door existed.
  • Risk and rollback: low. The command is new, a dry run by default, and writes only with --apply --yes. Nothing runs it automatically. Rollback is reverting this PR; rows it already rewrote stay rewritten, as for its three twins.
  • Look first: packages/cli/src/commands/migrate/audit-side-copies.ts (the --object refusal before the boot, and the two runner calls with objects and seal); packages/plugins/plugin-audit/src/side-copy-migration.ts (the one-line name change); packages/cli/src/commands/migrate/audit-side-copies.archive.integration.test.ts.
  • Two-minute check: pnpm --filter @objectstack/cli exec vitest run --project integration src/commands/migrate/audit-side-copies.archive.integration.test.ts shows 9 tests passing: dry run, --object, apply, re-run, archive, refusal.
  • What you need to do: nothing; the seat lands it.

What changes

  • os migrate audit-side-copies (new, packages/cli). It runs migrateSideCopies on the live sys_audit_log and sys_activity rows, then migrateArchivedSideCopies on the archive datasource sys_audit_log archives to. It is a twin of os migrate audit-key-material, line for line: the read-only dry-run boot, the absent-table read view, the redaction seal (ADR-0154 D7), the archive classification (examineArchiveTargets) and the exit codes. Its flags are the same (--database-url, --apply, --yes, --force, --json), plus one more:
    • --object, repeatable, takes sys_audit_log or sys_activity. It narrows the hot run and the archive run to the tables it names; without it, both tables are walked. A name that is not a copy table is refused with the family's envelope, OBJECT_NOT_FOUND and exit 1, before the boot, so a typo never narrows a run to nothing.
    • The report gives, per copy table, the copies read (scanned), rewritten or to rewrite (rewritten) and sealed-and-refused (refused), for the hot store and for each archive. The --json document is { database, apply, objects, report, archive, duration }. No line prints a value.
  • The rewrite's name (packages/plugins/plugin-audit/src/side-copy-migration.ts). A redaction amendment now records rewritten_by: 'os migrate audit-side-copies' instead of side-copy-migration.
  • Docs. content/docs/deployment/cli.mdx gets a table row, a #### os migrate audit-side-copies section, and the command added to the read-only-boot and sealed-rows paragraphs. content/docs/upgrading.mdx gets an "Upgrading from 18.4.0 or earlier" line. The sibling migrations are documented in these two places; the plugin-audit README documents none of them.
  • Family rosters. The new command joins every roster its twins sit in: audit-redaction-seal.contract.test.ts, migrate-confirmation-exit.pin.test.ts, json-stdout-purity.e2e.test.ts, schema-migrate.one-shot-family.integration.test.ts, and data-commands.absent-database.integration.test.ts (with a seeded live sys_activity copy, so the hot activity path is driven too).

The name, and why

Round 3 of the #33117 contract review said: "The rewrite records its amendments as side-copy-migration; the two precedents record the command name (os migrate audit-key-material, os migrate audit-mail-bodies). Settle the name when the door lands."

  • Command name audit-side-copies. The three siblings are named audit- plus what they rewrite: audit-metadata-bodies, audit-mail-bodies, audit-key-material. This rewrite removes the columns of the list side-copy-columns.ts holds (SIDE_COPY_COLUMNS), as audit-key-material removes the list key-material-copy.ts holds. audit-approval-payloads would name the only entry today, but the list is keyed by object and built to take more, so the name follows the list.
  • Amendment name os migrate audit-side-copies. All three precedents record the full command (os migrate audit-...) as rewritten_by, so an operator reading sys_audit_amendment finds the command to re-run. The old name never shipped in a release: feat(approvals,mcp): an approver's agent lists the approvals waiting on them over MCP #33117's changeset is still pending. A row amended on a pre-release build keeps the old name, which the changeset says.
  • ADR-0154 slice P4b3 will make os migrate audit-* --apply hold a database session lock. This command matches that pattern and takes the same --apply path as its twins, so P4b3 covers it with no special case. This PR builds no lock.

Tests

Every new pin was run red before the code existed. The command file was held out of the tree, and plugin-audit still recorded the old name.

  • Red, at 0c23193ab (tests only):
    • audit-side-copies.archive.integration.test.ts: 7 failed, all with Error: command migrate:audit-side-copies not found. Test 7 ("no run prints a sentinel") passed, as it must when nothing runs.
    • audit-redaction-seal.contract.test.ts: failed with ENOENT ... audit-side-copies.ts.
    • audit-seal-redaction-live.integration.test.ts: 1 failed, 16 passed. Expected "os migrate audit-side-copies", received "side-copy-migration".
  • Green, at 34582583d:
    • audit-side-copies.archive.integration.test.ts, 9 cases:
      • 0: the fixture is real (the real Archiver moved 3 copies, 2 of them carrying the column).
      • 1: dry run. Per table, hot sys_audit_log 1 scanned / 1 to rewrite and archive 2 / 2. Both stores are byte-identical afterwards.
      • 1b: the human face prints the same counts per table and per store.
      • 2: --object sys_activity --apply reads only sys_activity, has no archive entry, and leaves both stores unchanged.
      • 3: --apply leaves 0 carrying copies in either store and reports what it wrote. Every other key, column and the unlisted object's row is unmoved.
      • 4: the re-run rewrites nothing.
      • 5: the copy that was hot when the command ran is archived clean.
      • 6: --object sys_approval_request is refused with OBJECT_NOT_FOUND, exit 1.
      • 7: no sentinel is printed.
    • data-commands.absent-database.integration.test.ts: the new door answers empty work on a missing database, and on the booted control it rewrites 1 sys_audit_log and 1 live sys_activity copy.
    • schema-migrate.one-shot-family.integration.test.ts: the dry run writes nothing and --apply behaves as its family does.
    • The live amendment pin: a sealed approval-request copy is amended, rewritten, and reads redacted under rewritten_by: 'os migrate audit-side-copies'.

No separate ablation was run. The red run above is the before-and-after for each pin: the behaviour is new, and the same files go from red to green with only the implementation added.

Acceptance notes

  • sys_activity declares no archive target, so --object sys_activity reports archive: []. Case 2 pins that.
  • The archive classification the twins share (none / not-connected / unknown) is pinned in audit-key-material.archive.integration.test.ts and audit-mail-bodies.archive.integration.test.ts. It is not repeated here, because this command calls the same examineArchiveTargets.
  • docs/adr/0154-...md lists the three earlier rewrites by command. It is not edited here: the ADR is a decision record, not a roster.

Verification

All readings are at head 34582583d (worktree cut from origin/main 4bba8b8f0).

Local runs
  • pnpm --filter '@objectstack/cli^...' build under the verify lock: VERDICT command-exit 0.
  • pnpm --filter @objectstack/plugin-audit typecheck: VERDICT command-exit 0.
  • pnpm --filter @objectstack/plugin-audit exec vitest run: Test Files 93 passed (93), Tests 1502 passed (1502), VERDICT command-exit 0.
  • pnpm --filter @objectstack/cli typecheck (tsc plus check:test-typecheck): VERDICT command-exit 0.
  • pnpm --filter @objectstack/cli exec vitest run --project integration on the three touched integration files: Test Files 3 passed (3), Tests 240 passed (240), VERDICT command-exit 0.
  • pnpm --filter @objectstack/cli exec vitest run --project unit: Test Files 418 passed and 2 failed (420); Tests 5944 passed, 29 skipped.
    • The 2 failures are test/published-subpath-console.pin.test.ts and test/published-subpath-hook-body.pin.test.ts. Both refused with "packages/cli is not built (./dist/index.js is absent)", a missing-prerequisite refusal, not a finding. The closure build does not build packages/cli itself. The touched migrate-confirmation-exit.pin.test.ts and audit-redaction-seal.contract.test.ts are in the 418 that passed.
  • test/json-stdout-purity.e2e.test.ts: NOT MEASURED. Reason: the verify lock queue-timed out (exit 99) behind another worktree's holder. CI runs it.
  • eslint --no-inline-config on the 9 changed .ts files: exit 0.
  • node scripts/check-test-source-alias.mjs: exit 0. node scripts/check-nul-bytes.mjs: exit 0.
  • node scripts/pm/dispatch-gates.mjs --commands: 103 families derived. All 103 were run, and --ran reconciles 103/103.
    • 96 exited 0.
    • 7 exited 3 (PREREQUISITE NOT MET, so NOT MEASURED here). CI runs each on a built tree:
      • check:i18n, check:i18n-coverage, check:i18n-walk-parity, check:type-check-debt: "the workspace CLI is not built".
      • check:dual-build-cjs-loads: a package with no dist/.
      • spec check:skill-examples: client-react not built.
      • check-plugin-teardown-shape --self-test: the shallow clone cannot reach its pinned fixture.

Human Minimum

  • 1. Schemas start as Zod; packages/spec holds no runtime logic. (packages/spec not touched.)
  • 2. Every name I added uses the casing for its kind.
  • 3. No formatter ran; eslint on the changed files passes.
  • 4. One issue, one branch off an up-to-date main, one pull request.
  • 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset.
  • 6. packages/spec not touched.
  • 7. No hand edits to content/docs/references/, packages/*/CHANGELOG.md or content/docs/releases/.
  • 8. Title, body and comments are in English.
  • The Before Submitting list in CONTRIBUTING.md is done.

🤖 Generated with Claude Code

https://claude.ai/code/session_016WV4cz2MxDkQYCC4U8indM

…d the rewrite's amendment name before the code

The archive integration suite drives the command over the hot tables and an
archive datasource (dry run, --object, apply, re-run, refusal); the family
rosters gain the new member; the live redaction suite pins the name a sealed
row's amendment records. Docs and the changeset say how to run it.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4cz2MxDkQYCC4U8indM
…write, hot and archive

The command drives plugin-audit's migrateSideCopies and
migrateArchivedSideCopies with audit-key-material's shape (read-only dry run
by default, --apply/--yes/--force/--json, the redaction seal, the archive
classification and exit codes) plus a repeatable --object over the two copy
tables; any other name is refused OBJECT_NOT_FOUND before the boot. The
rewrite's redaction amendments now name it 'os migrate audit-side-copies', as
the twins name theirs.

Co-Authored-By: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4cz2MxDkQYCC4U8indM
@objectstack-fleet objectstack-fleet Bot added domain:server Domain lane — seat card indexed by label:pm:seat lease:A2 labels Nov 15, 2026
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

This PR changes 2 package(s): @objectstack/cli, @objectstack/plugin-audit, touching 5 documentable anchor(s).

11 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:

  • content/docs/data-modeling/drivers.mdx (via OS_DATABASE_URL (literal, a string literal in flags))
  • content/docs/data-modeling/external-datasources.mdx (via OS_DATABASE_URL (literal, a string literal in flags))
  • content/docs/deployment/backup-restore.mdx (via OS_DATABASE_URL (literal, a string literal in flags))
  • content/docs/deployment/cli.mdx (via OS_DATABASE_URL (literal, a string literal in flags), database_busy (literal, a string literal in rewrite), os migrate audit-side-copies (command, read off packages/cli/src/commands/migrate/audit-side-copies.ts))
  • content/docs/deployment/environment-variables.mdx (via OS_DATABASE_URL (literal, a string literal in flags))
  • content/docs/deployment/production-readiness.mdx (via OS_DATABASE_URL (literal, a string literal in flags))
  • content/docs/deployment/self-hosting.mdx (via OS_DATABASE_URL (literal, a string literal in flags))
  • content/docs/deployment/single-project-mode.mdx (via OS_DATABASE_URL (literal, a string literal in flags))
  • content/docs/getting-started/your-first-project.mdx (via OS_DATABASE_URL (literal, a string literal in flags))
  • content/docs/plugins/index.mdx (via OS_DATABASE_URL (literal, a string literal in flags))
  • content/docs/upgrading.mdx (via os migrate audit-side-copies (command, read off packages/cli/src/commands/migrate/audit-side-copies.ts))
What this run could not see

Coarse fallback — 45 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json c32bb6ccbb293a4bda77010ce7ad416fcfeb1138 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 8821ca81af391c7f57cb07055caef997cba14f5e — the merge of head 34582583df4b86a5250a4adefee4d4f7a3ae3521 into base c32bb6ccbb293a4bda77010ce7ad416fcfeb1138, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 8821ca81af391c7f57cb07055caef997cba14f5e && git checkout 8821ca81af391c7f57cb07055caef997cba14f5e
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin c32bb6ccbb293a4bda77010ce7ad416fcfeb1138 34582583df4b86a5250a4adefee4d4f7a3ae3521 && git checkout -B drift-repro c32bb6ccbb293a4bda77010ce7ad416fcfeb1138 && git merge --no-ff 34582583df4b86a5250a4adefee4d4f7a3ae3521

node scripts/docs-audit/affected-docs.mjs --json c32bb6ccbb293a4bda77010ce7ad416fcfeb1138

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

Advisory only, and a precision-first one (#9192): a page is listed because it names a
symbol, wire route or SDK method this diff touched — not because it mentions a changed
package. Each row says which anchor put it there, so a wrong row is reportable rather than
merely annoying. To re-verify, run the docs-accuracy-audit workflow scoped to these files:
node scripts/docs-audit/affected-docs.mjs c32bb6ccbb293a4bda77010ce7ad416fcfeb1138 → pass the list as
args.docs, on the commit named under Which tree this was computed on.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

Contract-review-claim: session_016WV4d1PGptBW3QRQNmy5e6 · head 3458258 · 2026-11-15T02:39Z

review#3.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

Contract review

Served-tier: TIER_DEFAULT
Head-sha: 34582583df4b86a5250a4adefee4d4f7a3ae3521
Local-runs: none

Read: the PR's two commits on top of main, 0c23193a (pins, docs, changeset) and 34582583 (code). That is 12 files, +861/−11. I diffed the new command line by line against its twin audit-key-material.ts and checked each claim against the code at this head. CI was still running when I read it: 31 success, 23 skipped, 7 in progress, 1 cancelled, 0 failed.

① Derived judgments

The driver is the twin, plus --object. A diff against packages/cli/src/commands/migrate/audit-key-material.ts shows only names, wording, the --object block and the objects field it threads through. Each point the area asked about:

  • Dry run writes nothing. A dry run boots read-only with deferSchemaDdl and readOnlyProbe (audit-side-copies.ts:220, twin :191), and both runners get apply: false (:256, :265). Pin 1 compares both SQLite files row for row before and after the dry run (audit-side-copies.archive.integration.test.ts:301-302).
  • --apply needs confirmation. --apply without --yes exits 1 under --json or when stdin is not a TTY, and prompts on a TTY (:180-198, twin :151). The command joins the migrate-confirmation-exit.pin.test.ts roster (:257).
  • Refusals are counted. refused adds the hot report and every archive report (:268). Either a refusal or a failure exits 1 on both output paths (:273, :341, twin :247, :315). The human report prints N sealed and refused per table and per store (:283, :291).
  • Archive classification. It uses the shared examineArchiveTargets and archiveFailureCount from utils/ledger-copy-archive.ts, with the same four status branches and messages (:260-266, :294-324). The only change is tables: objects instead of the fixed list, so --object sys_activity gives archive: []. Pin 2 measures that (test:319).
  • Exit codes. They match the twin on every path: busy without --force, confirmation required, boot error, a failure, a refusal, and an archive that is not-connected or unknown. The one new path, an unknown --object, exits 1.
  • --json stdout stays pure. The runner logger goes to stderr under --json (:238-239), and every error path uses emitJson. The refusal path runs before reserveStdoutForJson, but it prints nothing except the one emitJson document, and pin 6 parses its whole stdout as JSON (test:370). The command joins json-stdout-purity.e2e.test.ts (:136-138).
  • --object is checked before the boot. The check runs at :136-151, before probeMigrationTarget (:155), the confirmation (:180), composeRedactionSeal (:205) and bootSchemaStack (:212). The only thing it loads first is @objectstack/plugin-audit, for SIDE_COPY_TABLES. Duplicate names are dropped, and the table order comes from SIDE_COPY_TABLES, not from the flag order.

Audit data stays safe.

  • The seal is wired as in the twin. composeRedactionSeal() runs before the boot (:205), its plugins join the boot (:215), and the same seal object goes to the hot run (:256) and to every archive run (:265). The command joins audit-redaction-seal.contract.test.ts (:25).
  • The rewrite goes through the shared runLedgerCopyRewrite (side-copy-migration.ts:161-182). That is the code path that amends a sealed row before rewriting it, or refuses the row. So a sealed or chained row is never rewritten without its amendment.
  • The live suite (audit-seal-redaction-live.integration.test.ts) now amends a sealed sys_approval_request copy through migrateSideCopies. It asserts that the copy loses payload_json, that the amendment's rewritten_by is os migrate audit-side-copies, and that the verifier reads the row as redacted.

The rewritten_by rename.

  • The value is free text. The amendment writer signs it into the body (amendment-writer.ts:414), and the verifier reads it back as text (signed-body.ts:338). Nothing checks it against a list of names, so an amendment signed earlier under side-copy-migration still verifies.
  • The old value never shipped. side-copy-migration.ts does not exist at tag @objectstack/plugin-audit@18.4.0, the newest release (published 2026-11-13T12:33Z): the contents API answers 404 at that ref. feat(approvals,mcp): an approver's agent lists the approvals waiting on them over MCP #33117 (3eac63a9, 2026-11-13T21:02Z) added it after that release, and its changeset .changeset/mcp-read-tools-ai-readable-system-object.md is still pending.

The pins measure the claims, with one gap, N1. Cases 0–5 drive the real Archiver and the source CLI. They compare both stores row for row, check which keys survive in a rewritten copy (test:347-349), check that the same-named column on an unlisted object is kept (:341-342), and check that a re-run changes nothing (:357). data-commands.absent-database.integration.test.ts adds a live sys_activity copy, so the hot activity path rewrites a row (rewritten: 1). Pin 2's sys_activity has no rows in this fixture. What it shows is the exclusion: sys_audit_log is left alone in both stores.

The docs match the behaviour. In cli.mdx, the section's flags, the OBJECT_NOT_FOUND refusal, the per-table and per-store report and the archive cross-reference match the code. The sealed-rows paragraph and the absent-database paragraph now list the new command. The upgrading.mdx line says "from 18.4.0 or earlier", which is right, because the writer change it cleans up after is not released yet.

② Semver level

  • Clause-②: yes (widening) is right. The PR adds a CLI command, the --object flag and an objects member in the --json document. Nothing that was accepted before is refused now. --object is new, so refusing an unknown value narrows nothing.
  • The rewritten_by change is not a narrowing. It is a stored value, and only new amendments carry it. No reader matches on it. No release ever wrote side-copy-migration, so no deployment holds an amendment that a reader could misread. A row amended on a pre-release build keeps its signed value and still verifies. The changeset says this.
  • Patch for both packages is right. No authorable metadata or spec shape moves, so Metadata-protocol: none holds. Both declaration lines start a line in the PR body and in .changeset/33155-audit-side-copies-door.md. No !, BREAKING banner or ADR-0087 marker is owed.

③ Boundary flags

None. The diff stays in packages/cli, the plugin-audit migration's name and comment, two docs pages and the family rosters. It builds no lock; ADR-0154 P4b3 is left to its own slice, as the PR says.

Nits (none blocks).

  • N1. Pin 6 is titled "refused before anything is read" (audit-side-copies.archive.integration.test.ts:367), but it measures only exit 1, OBJECT_NOT_FOUND and an unchanged hot store. A refusal after the boot would pass it too. To pin "before the boot", point that run's --database-url at a file that does not exist and assert the file is still absent afterwards. Run with --apply --yes, the plain boot would create it.
  • N2. The cli.mdx:1485 table row now names --object and then says "No flag; idempotent". The siblings use "No flag" to mean no sys_migration flag is recorded, but next to a CLI flag it reads as a contradiction. "Records no sys_migration flag" would be exact.
  • N3. Three code-comment rosters of the family were not updated: utils/ledger-copy-archive.ts:7 names two commands, audit-seal/amendment-writer.ts:24-26 names three, and utils/schema-migrate.ts:1276-1279 says composeDeclaredDatasources is set "by nothing else". That last one was already stale, because os audit verify sets it too.
  • N4. The --object refusal at audit-side-copies.ts:137-142 repeats refuseUndeclaredObjects (utils/migrate-object-scope.ts:73-91) with a different message. Calling the helper with SIDE_COPY_TABLES as the declared set would keep one envelope builder. The helper's message says "this deployment declares", so it would need a small message option.

Implemented-by: claude/area-A2-33155
Reviewed-by: session_016WV4d1PGptBW3QRQNmy5e6

VERDICT: PASS

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#5 · os-elon-musk · session_016WV4cz2MxDkQYCC4U8indM

ACCEPT: head 3458258

  • Review: review#3 PASS at this head (6888103179). The rewritten_by rename is not a narrowing: the old value shipped in no release, and the verifier reads the value as free signed text. The four nits, N1 to N4, are not blocking and are left for a follow-up touch.
  • CI at this head: 39 success and 17 expected skips, nothing unexpected. One Check Changeset run was cancelled because a newer run of the same check superseded it; both of the other runs succeeded.
  • Governed-surface predicate: not governed. 872 changed lines (≤ 3000).
  • Base: mergeable state is clean, and the head is 12 commits behind main. The PR touches @objectstack/cli, @objectstack/plugin-audit and docs, and none of these is a shared package under the before-arming rule.
  • Scope: closes plugin-audit: give the at-rest side-copy rewrite (migrateSideCopies / migrateArchivedSideCopies) an operator door #33155 (os migrate audit-side-copies).

Landing: ready for review, then auto-merge (the area rule for PRs that passed review, 2026-11-15T03:10Z).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation domain:server Domain lane — seat card indexed by label:pm:seat size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-audit: give the at-rest side-copy rewrite (migrateSideCopies / migrateArchivedSideCopies) an operator door

2 participants